package com.example.networkcore.Interceptor

import okhttp3.Interceptor
import okhttp3.Response

class CacheInterceptor : Interceptor {

    override fun  intercept(chain: Interceptor.Chain) : Response {
        val request = chain.request();
        var originResponse = chain.proceed(request);

        //设置响应的缓存时间为60秒，即设置Cache-Control头，并移除pragma消息头，因为pragma也是控制缓存的一个消息头属性
        originResponse = originResponse.newBuilder()
            .removeHeader("pragma")
            .header("Cache-Control", "max-age=60")
            .build();

        return originResponse;
    }
}